// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: "te-6b32b2"
})

const db = cloud.database()
// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const {
      OPENID
    } = cloud.getWXContext()
    const templateId = 'ylFE4cuyk52n_UKt1otNX-FarynIEd6wwtiNP8v3MFU'

    return await cloud.openapi.subscribeMessage.send({
      touser: OPENID,
      page:  `/pages/blog-comment/blog-comment?blogId=${event.blogId}`,
      lang: 'zh_CN',
      data: {
        phrase2: {
          value: '评论成功'
        },
        thing3: {
          value: event.content
        }
      },
      templateId: templateId,
      // miniprogramState: 'developer'
    })
    return result
  } catch (err) {
    return err
  }
}